<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="灯杆名称">
              <a-input placeholder="请输入灯杆名称" v-model="queryParam.lightName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="灯杆编号">
              <a-input placeholder="请输入灯杆编号" v-model="queryParam.lightCode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="云盒类型">
                <a-input placeholder="请输入云盒类型" v-model="queryParam.boxType"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="在线状态">
                <j-switch placeholder="请选择在线状态" v-model="queryParam.olStatus"  query></j-switch>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备状态">
                <a-input placeholder="请输入设备状态" v-model="queryParam.status"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属区域">
                <a-input placeholder="请输入所属区域" v-model="queryParam.areaId"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus"  style="margin-left: 8px">新增</a-button>  
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
 
    <!-- table区域-begin -->
    <div> 
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <light-pole-modal ref="modalForm" @ok="modalFormOk"></light-pole-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LightPoleModal from './modules/LightPoleModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'LightPoleList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LightPoleModal
    },
    data () {
      return {
        description: '灯杆管理管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'灯杆名称',
            align:"center",
            dataIndex: 'lightName'
          },
          {
            title:'灯杆编号',
            align:"center",
            dataIndex: 'lightCode'
          },
          // {
          //   title:'经度',
          //   align:"center",
          //   dataIndex: 'gwlongitude'
          // },
          // {
          //   title:'纬度',
          //   align:"center",
          //   dataIndex: 'gwlatitude'
          // },
          {
            title:'云盒zigbee 中心地址',
            align:"center",
            dataIndex: 'boxId'
          },
          {
            title:'云盒类型',
            align:"center",
            dataIndex: 'boxType_dictText'
          },
          {
            title:'云盒mac地址',
            align:"center",
            dataIndex: 'boxMac'
          },
          {
            title:'在线状态',
            align:"center",
            dataIndex: 'olStatus_dictText', 
          },
          {
            title:'设备状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          // {
          //   title:'所属区域',
          //   align:"center",
          //   dataIndex: 'areaId_dictText'
          // },
          // {
          //   title:'所属分组id',
          //   align:"center",
          //   dataIndex: 'groupId'
          // },
          // {
          //   title:'所属项目id',
          //   align:"center",
          //   dataIndex: 'projectId'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/corp/lightPole/list",
          delete: "/corp/lightPole/delete",
          deleteBatch: "/corp/lightPole/deleteBatch",
          exportXlsUrl: "/corp/lightPole/exportXls",
          importExcelUrl: "/corp/lightPole/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.$set(this.dictOptions, 'olStatus', [{text:'是',value:'Y'},{text:'否',value:'N'}])
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'lightName',text:'灯杆名称',dictCode:''})
        fieldList.push({type:'string',value:'lightCode',text:'灯杆编号',dictCode:''})
        fieldList.push({type:'string',value:'gwlongitude',text:'经度',dictCode:''})
        fieldList.push({type:'string',value:'gwlatitude',text:'纬度',dictCode:''})
        fieldList.push({type:'string',value:'boxId',text:'云盒zigbee 中心地址',dictCode:''})
        fieldList.push({type:'string',value:'boxType',text:'云盒类型',dictCode:'boxType'})
        fieldList.push({type:'string',value:'boxMac',text:'云盒mac地址',dictCode:''})
        fieldList.push({type:'switch',value:'olStatus',text:'在线状态:0.掉线; 1.在线'})
        fieldList.push({type:'string',value:'status',text:'设备状态: 0.禁用; 1. 启用; 2.报警',dictCode:''})
        fieldList.push({type:'string',value:'areaId',text:'所属区域',dictCode:''})
        fieldList.push({type:'popup',value:'groupId',text:'所属分组id', popup:{code:'tb_group',field:'id',orgFields:'id',destFields:'group_name'}})
        fieldList.push({type:'popup',value:'projectId',text:'所属项目id', popup:{code:'tb_project',field:'id',orgFields:'id',destFields:'project_name'}})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>